/* 
 * Copyright (c) 2010, Avdhesh yadav.
 * http://www.avdheshyadav.com
 * Contact: avdhesh.yadav@gmail.com
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */

package com.avdy.p4j.sample.client.view;


import org.gwt.mosaic.override.client.FlexTable;
import org.gwt.mosaic.override.client.FlexTable.FlexCellFormatter;
import org.gwt.mosaic.ui.client.table.AbstractScrollTable.ColumnResizePolicy;
import org.gwt.mosaic.ui.client.table.AbstractScrollTable.ResizePolicy;
import org.gwt.mosaic.ui.client.table.FixedWidthFlexTable;
import org.gwt.mosaic.ui.client.table.FixedWidthGrid;
import org.gwt.mosaic.ui.client.table.ScrollTable;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Widget;
import com.avdy.p4j.sample.client.presenter.BookListPresenter;

public class BookListView extends Composite implements BookListPresenter.Display
{
	private ScrollTable scrollTable;
	private FlexTable layout = new FlexTable();

	public BookListView()
	{
		layout.setWidth("600px");
		layout.setCellPadding(0);
		layout.setCellSpacing(5);
		FlexCellFormatter formatter = layout.getFlexCellFormatter();

		FixedWidthGrid dataTable = new FixedWidthGrid(1,3);

		FixedWidthFlexTable headerTable = new FixedWidthFlexTable();
		headerTable.setHTML(0, 0, "ISBN");
		headerTable.setHTML(0, 1, "Title");
		headerTable.setHTML(0, 2, "Author");
		scrollTable = new ScrollTable(dataTable, headerTable);
		scrollTable.setResizePolicy(ResizePolicy.FIXED_WIDTH);
		scrollTable.setColumnResizePolicy(ColumnResizePolicy.DISABLED);
		scrollTable.setHeight("400px");
		scrollTable.setCellPadding(10);
		layout.setWidget(0, 1, scrollTable);
		formatter.setWidth(0, 1, "100%");
	    formatter.setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP);
		initWidget(layout);
	}


	/**
	 * 
	 */
	public FixedWidthGrid getDataTable()
	{
		return scrollTable.getDataTable();
	}


	public Widget asWidget()
	{
		return this;
	}
}
